package com.kuang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
//@ResponseBody
public class LoginController {
    @RequestMapping("/login")
    public String login(HttpServletRequest request, Model model, HttpSession session){
        //System.out.println("用户名："+username+",密码："+password);
        System.out.println("我看看是否到这里了");
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        if(username==null){//这一步是为了:如果用户未登录,则不判断用户名和密码的正确性.
            return "login";//去template目录下找login.html，在那里面有各个填空等待插入信息。
        }
        if (!StringUtils.isEmpty(username) && "123456".equals(password)){
            session.setAttribute("loginUser",username);
            //return "redirect:/index.html";
            return "redirect:/index.html";
        }else {
            model.addAttribute("msg","用户名或密码错误！");
            return "login";//去template目录下找login.html，在那里面有各个填空等待插入信息。
        }
    }
}
